Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement daily worked time rounding #248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sant0s12
Copy link

@sant0s12 sant0s12 commented Jul 2, 2023

Attempts to resolve #147.

At the moment it does not work when generating reports.

Copy link
Owner

@mathisdt mathisdt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sant0s12,
thanks for your pull request! I'm sorry it took me so long to review it - I just started into a new job which took some adjusting, and then I was away on family vacation. But now I provided some feedback (see code comments).

For your feature to be complete, it will be necessary to also include rounding for the reports if it's activated. The users won't tolerate different numbers in the app and in the reports (there already were some issues reported regarding this in the past).

But more importantly the rounding formula seems to cover only some cases. As I wrote in the code comment I'd like to have a unit test for this calculation. If you are unsure how to approach this, I can also help out with that, but at the moment the rounding seems not to work correctly. So if you don't add a unit test, please at least fix the method roundUpToMultiple().

Thanks again for your contribution! It didn't deserve to be ignored for so long!

if (handleFlexiTime) {
this.flexiReset = timerManager.getFlexiReset();
} else {
this.flexiReset = FlexiReset.NONE;
}

this.roundingEnabled = preferences.getBoolean(Key.ROUNDING_ENABLED.getName(), false);
if (preferences.getBoolean(Key.ROUNDING_ENABLED.getName(), false)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be

if (roundingEnabled) {

instead (we just evaluated the same statement used here).

if (handleFlexiTime) {
this.flexiReset = timerManager.getFlexiReset();
} else {
this.flexiReset = FlexiReset.NONE;
}

this.roundingEnabled = preferences.getBoolean(Key.ROUNDING_ENABLED.getName(), false);
Copy link
Owner

@mathisdt mathisdt Aug 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this. is superfluous here (above in this.flexiReset it's also superfluous).

if (multiple == 1) {
return value;
} else {
return (value + multiple - 1) / multiple * multiple;
Copy link
Owner

@mathisdt mathisdt Aug 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work in all cases. For the inputs value = 43, multiple = 15 it should round to 45. But it doesn't, the method would return 57 with these inputs.

To be on the safe side, I'd recommend creating a unit test for the calulation method where some "normal" cases and many (if not all) of the edge cases are checked. For a start you can copy TimeCalculatorTest to TimeCalculatorV2Test and adjust the content accordingly.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible values of multiple are: 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60

But probably only the values 5, 10, 15, 30 and 60 will be used in real life...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's weird. I'll write some tests for it.

Also, I do use 6 as a multiple myself since my work tracks time to an accuracy of 0.1 hours. Therefore I think it makes sense to leave it up to the user to choose any divisor of 60 :)

@@ -361,7 +374,7 @@ public void calculateNextDay() {

currentDayHasEvents = (events != null && !events.isEmpty());

workedTime += calculateWorkTime(events);
workedTime += roundUpToMultiple(calculateWorkTime(events), smallestTimeUnit);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be wrapped in an if block to only execute it when required:

if (roundingEnabled) {
   workedTime += roundUpToMultiple(calculateWorkTime(events), smallestTimeUnit);
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While glancing over this again, my previous comment doesn't make sense. The calculateWorkTime(events) would also be only executed if my code snippet was used, so it better should be like:

if (roundingEnabled) {
	workedTime += roundUpToMultiple(calculateWorkTime(events), smallestTimeUnit);
} else {
	workedTime += calculateWorkTime(events);
}

Comment on lines +161 to +162
} else {
this.smallestTimeUnit = 1;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else part can be left out if the variable is initialized with the value 1 above:

private final int smallestTimeUnit = 1;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I am missing something, but I get an error if I do that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my bad - the final keyword is the problem. With

private int smallestTimeUnit = 1;

it works.

@sant0s12
Copy link
Author

Hi @mathisdt, thanks a lot for your feedback. I'll take a look at it and implement your suggestions.

@Bugz777
Copy link

Bugz777 commented Sep 7, 2023

Hi @sant0s12,

I'm interested in seeing this feature deployed.
Are you still working on it?

@sant0s12
Copy link
Author

@Josic490 Yes, but I am a bit busy at the moment, don't know when I'll get around to it. Feel free to address @mathisdt feedback if you want! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request] Rounding of time entries
3 participants